<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Help\Widget;

use Think\Action;

/**
 * 评分widget
 * 用于动态调用分类信息
 */
class ScoreWidget extends Action
{


    public function render($row_id=0){
        $this->assign('row_id', $row_id);
        $this->display('Widget/score_render');
    }

    public function score($title = '', $content = '',$row_id=0,$score=0 ,$can=1)
    {
        $this->assign('content', $content);
        $this->assign('title', $title);
        $this->assign('row_id', $row_id);
        $this->assign('score', $score);
        $this->assign('can', $can);
        $this->display('Widget/score');
    }

    public function score_arr($title = '', $content = '',$row_id=0,$score=0 ,$can=1)
    {
        $this->assign('content', $content);
        $this->assign('title', $title);
        $this->assign('row_id', $row_id);
        $this->assign('score', $score);
        $this->assign('can', $can);
        $this->display('Widget/score_arr');
    }

    public function avg($uid=0){

        $help_count = D('Help/HelpAttend')->getHelpCountByUid($uid);
        $rate=query_user(array('rate'),$uid);
        $rate=$rate['rate'];


        $all_score = D('HelpEvaluate')->where(array('to_uid'=>$uid))->field('punctual,trustworthy,technique,attitude')->select();
        $punctual =0;
        $trustworthy=0;
        $technique=0;
        $attitude=0;
        foreach($all_score as $k=>$v){
            $punctual += $v['punctual'];
            $trustworthy  += $v['trustworthy'];
            $technique += $v['technique'];
            $attitude += $v['attitude'];
        }
        $avg['punctual'] =number_format($punctual/$evaluate_count,1);
        $avg['trustworthy'] =number_format($trustworthy/$evaluate_count,1);
        $avg['technique'] =number_format($technique/$evaluate_count,1);
        $avg['attitude'] =number_format($attitude/$evaluate_count,1);
        $this->assign('uid',$uid);
        $this->assign('help_count',$help_count);
        $this->assign('rate',$rate);
        $this->assign('avg',$avg);
        $this->display(T('Help@Widget/score_avg'));
    }

}
